<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>业务处理-采购申请</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
			<div class="page_header"><a>采购申请</a></div>
			<div class="search">
			<form action="<%=basePath %>purchaseRequest/listPurchaseRequest.do" method="post"  class="form">
				<input type="hidden" name="currentPage" value="1">
				<p>
					<label>申请单号</label>
					<input type="text" class="form-control" name="applicationNo" value="${purchaseRequestPage.applicationNo }"></input>
					<label>提交人</label>
					<input type="text" class="form-control" name="commitName" value="${purchaseRequestPage.commitName }">
					<label>状态</label>
					<select name="status" class="form-control select">
						<option value="">全部</option>
						<option value="0" <c:if test="${purchaseRequestPage.status==0}">selected</c:if>>未提交</option>
						<option value="1" <c:if test="${purchaseRequestPage.status==1}">selected</c:if>>已提交</option>
						<option value="2" <c:if test="${purchaseRequestPage.status==2}">selected</c:if>>审核中</option>
						<option value="3" <c:if test="${purchaseRequestPage.status==3}">selected</c:if>>已通过</option>
						<option value="4" <c:if test="${purchaseRequestPage.status==4}">selected</c:if>>未通过</option>
					</select>
					<label>时间</label>
					<input type="text" class="form-control" name="lastProcessingTime1" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" value="${purchaseRequestPage.lastProcessingTime1 }"></input>
					<label>至</label>
					<input type="text" class="form-control" name="lastProcessingTime2" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" value="${purchaseRequestPage.lastProcessingTime2 }"></input>
				</p>
				<p>
					<label>部门</label>
					<select name="deptID" class="form-control select">
						<option value="">全部</option>
						<c:forEach items="${organizations }" var="org">
							<option value="${org.organizationid }" <c:if test="${purchaseRequestPage.deptID==org.organizationid}">selected</c:if>>${org.organizationname }</option>
						</c:forEach>
					</select>
					<label>邮轮</label>
					<select name="cruiseID" class="form-control select">
						<option value="">全部</option>
						<c:forEach items="${cruiseList }" var="cruise">
							<option value="${cruise.cruiseID }" <c:if test="${purchaseRequestPage.cruiseID==cruise.cruiseID}">selected</c:if>>${cruise.cruiseName }</option>
						</c:forEach>
					</select>
					<label>申请说明</label>
					<input type="text" class="form-control" name="explains" value="${purchaseRequestPage.explains }"></input>
					<span class="btn">
						<input type="submit" class="btn btn1" value="查询"></input>
						<input type="button" class="btn btn2" value="清空" onclick="clearSearchParam();"></input>
						<c:if test="${isAdd }">
							<input type="button" class="btn btn1" value="新增" onclick="location.href='<%=basePath %>purchaseRequest/toAdd.do'"></input>
							<input type="button" class="btn btn2"value="复制" onclick="toCopyPurchaseRequest();"></input>
						</c:if>
						<input type="button" class="btn btn1" value="编辑" onclick="toEditPurchaseRequest();"></input>
						<input type="button" class="btn btn_danger" value="删除" onclick="toDeletePurchaseRequest();"></input>
					</span>
				</p>
				</form>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th></th>
							<th style="width:200px;">操作</th>
							<th>单号</th>
							<th>申请说明</th>
							<th>品项数</th>
							<th>状态</th>
							<th>创建时间</th>
							<th>提交人</th>
							<th>部门</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${prList }" var="pr" varStatus="i">
							<tr id="${pr.purchaseRequisitionID }" onclick="selectRow(this);">
								<td>
								<label class="radio"><input type="radio" name="operatePurchaseRequest" value="${pr.purchaseRequisitionID }"><span class="radio_icon"></span></label>
								</td>
								<td>
									<a class="btn btn-xs btn1" onclick="editPurchaseRequest(${pr.purchaseRequisitionID });">编辑</a>
									<a class="btn btn-xs btn2" onclick="confirmCopyPurchaseRequest(${pr.purchaseRequisitionID });">复制</a>
								<c:if test="${pr.status=='0' }">
									<a class="btn btn-xs btn1" onclick="confirmSubmitPurchaseRequest(${pr.purchaseRequisitionID });">提交</a>
									<a class="btn btn-xs btn_danger" onclick="confirmDeletePurchaseRequest(${pr.purchaseRequisitionID });">删除</a>
								</c:if>
								</td>
								<td><a onclick="editPurchaseRequest(${pr.purchaseRequisitionID });">${pr.applicationNo}</a></td>
								<td>${pr.explains }</td>
								<td>${pr.pNumber }</td>
								<td>
									<c:if test="${pr.status==0 }">未提交</c:if>
									<c:if test="${pr.status==1 }">已提交</c:if>
									<c:if test="${pr.status==2 }">审核中</c:if>
									<c:if test="${pr.status==3 }">已通过</c:if>
									<c:if test="${pr.status==4 }">未通过</c:if>
								</td>
								<td><fmt:formatDate value="${pr.createDate }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
								<td>${pr.applicantName }</td>
								<td>${pr.organizationName }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
		</div>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>My97DatePickers/WdatePicker.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
	
	function clearSearchParam(){
		$(".search input:text").val("");
		$(".search select").val("");
	}
	
	function selectRow(obj){
		$(obj).find('input:radio[name="operatePurchaseRequest"]')[0].checked=true;
	}
	
	function toEditPurchaseRequest(){
		var radio=$('input:radio[name="operatePurchaseRequest"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要编辑的采购申请！");
			return;
		}
		editPurchaseRequest(radio.val());
	}
	
	function editPurchaseRequest(purchaseRequisitionID){
		location.href="<%=basePath %>purchaseRequest/toEdit.do?purchaseRequisitionID="+purchaseRequisitionID;
	}
	
	function toDeletePurchaseRequest(){
		var radio=$('input:radio[name="operatePurchaseRequest"]:checked');
		if(!radio.val()){
			Prompt.alert("删除提示","请先选中需要删除的采购申请！");
			return;
		}
		confirmDeletePurchaseRequest(radio.val());
	}
		
	function confirmDeletePurchaseRequest(id){
		var delFunc=function(){
			$.ajax({
				url:"<%=basePath %>purchaseRequest/delete.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "purchaseRequestid="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("删除提示","采购申请已删除！",Prompt.refresh);
					}else{
						Prompt.alert("提示","采购申请删除失败！");
					}
				},
				error :function(){
					Prompt.alert("删除提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要删除该采购申请吗?删除后无法恢复",delFunc);
	}
	
	function toSubmitPurchaseRequest(){
		var radio=$('input:radio[name="operatePurchaseRequest"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要提交的采购申请！");
			return;
		}
		confirmSubmitPurchaseRequest(radio.val());
	}
		
	function confirmSubmitPurchaseRequest(id){
		var delFunc=function(){
			$.ajax({
				url:"<%=basePath %>purchaseRequest/submitStatus.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "purchaseRequestid="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("提示","采购申请已提交！",Prompt.refresh);
					}else{
						Prompt.alert("提示","采购申请提交失败！");
					}
				},
				error :function(){
					Prompt.alert("提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要提交该采购申请吗?",delFunc);
	}
	
	function toCopyPurchaseRequest(){
		var radio=$('input:radio[name="operatePurchaseRequest"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要复制的采购申请！");
			return;
		}
		confirmCopyPurchaseRequest(radio.val());
	}
		
	function confirmCopyPurchaseRequest(id){
		var delFunc=function(){
			$.ajax({
				url:"<%=basePath %>purchaseRequest/copy.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "purchaseRequestid="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("提示","采购申请已成功复制！",Prompt.refresh);
					}else{
						Prompt.alert("提示","采购申请复制失败！");
					}
				},
				error :function(){
					Prompt.alert("提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要复制该采购申请吗?",delFunc);
	}
	</script>
</body>
</html>